package com.csoa.community.net;

import android.content.Context;
import android.os.AsyncTask;

import com.csoa.community.activity.BaseActivity;
import com.csoa.community.requests.AbstractRequest;

public abstract class BaseAsyncTask extends AsyncTask<AbstractRequest, Object, AbstractRequest> {
	protected BaseActivity.OnUICallback callback;
	protected Context activity;

	public BaseAsyncTask(Context activity, BaseActivity.OnUICallback callback) {
		this.callback = callback;
		this.activity = activity;
	}

	@Override
	protected void onPostExecute(AbstractRequest result) {
		if (!this.isCancelled()) {
			if (callback != null) {
				callback.onGetResult(result);
			}
		}
	}
	@Override
	protected void onProgressUpdate(Object... values) {
		// TODO Auto-generated method stub
		int progress = (Integer) values[0];
		String desc = values[1].toString();
		if (progress < 0) {
			
			if (callback != null) {
				callback.onProgress(progress, desc);
			}
			
			if (callback != null) {
				callback.onCancel();
			}
		}
	}


}
